package blog.service.impl;

import java.util.List;

import blog.dao.UserDao;
import blog.dao.impl.UserDaoImpl;
import blog.entities.User;
import blog.service.UserService;

public class UserServiceImpl implements UserService {

	private UserDao userDao = new UserDaoImpl();
	
	@Override
	public User userLogin(String username, String password) {
		User user = userDao.getUser(username, password);
		return user;
	}

	@Override
	public int userRegister(String username, String password) {
		int i = userDao.registerUser(username,password);
		return i;
	}

	
	
	@Override
	public int userRegister(Object... params) {
		int i = userDao.addUser(params);
		return i;
	}

	
	
	@Override
	public List<User> getSpecifiedUserList(Object... params) {
		return userDao.getUserByCondition(params);
	}

	@Override
	public List<User> getAllUser() {
		return userDao.getUserList();
	}

	@Override
	public boolean checkUserExist(String username, String password) {
		User user = userDao.getUser(username, password);
		if (user.getUsername().equals(username)) {
			if (user.getPassword().equals(password)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int userDelete(Object... params) {
		int update = 0;
		update = userDao.deleteUserByCondition(params);
		return update;
	}

	@Override
	public int userUpdate(int id, Object... params) {
		int update = 0;
		if (params != null && params.length > 0) {
			for (int i = 0; i < params.length; i += 2) {
				System.out.println("执行中,id=" + id + "(1:成功;0:失败)..." + userDao.updateUserByCondition(id, (String)params[i], (String)params[i + 1]));
			}
		}
		return update;
	}
	
	
	
	
}
